package com.easytake.emotioncat.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.easytake.emotioncat.dto.PageResult;
import com.easytake.emotioncat.entity.EmHelpEntity;
import com.easytake.emotioncat.mapper.EmHelpMapper;
import com.easytake.emotioncat.service.IEmHelpService;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 常见问题,操作记录 服务实现类
 * </p>
 *
 * @author baomidou
 * @since 2022-11-07
 */
@Service
public class EmHelpServiceImpl extends ServiceImpl<EmHelpMapper, EmHelpEntity> implements IEmHelpService {

    @Override
    public PageResult<EmHelpEntity> getListByPage(Integer pageNo, Integer pageSize, Integer category) {
        EmHelpMapper mapper = this.getBaseMapper();
        Page<EmHelpEntity> page = Page.of(pageNo, pageSize);
        QueryWrapper<EmHelpEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(EmHelpEntity::getCategory, category);
        OrderItem orderItem = OrderItem.desc("create_time");
        List<OrderItem> orderItemList = new ArrayList<>();
        orderItemList.add(orderItem);
        page.setOrders(orderItemList);
        IPage<EmHelpEntity> entityIPage = mapper.selectPage(page, queryWrapper);
        PageResult<EmHelpEntity> pageResult = new PageResult(entityIPage);
        return pageResult;
    }
}
